package ljye.com.ljye.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import ljye.com.ljye.R;

/**
 */

public class Class_GridViewAdapter extends BaseAdapter {
    Context context;
    List<String> list;
    private int clickStatus = 0;//默认第一个
    public Class_GridViewAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        if (view == null) {
            view = layoutInflater.inflate(R.layout.class_item_gridview, null);
            TextView tv =  (TextView) view.findViewById(R.id.tv);
            tv.setText(list.get(i));

            if (clickStatus==i) {
                tv.setBackgroundResource(R.drawable.orange_line_bg);
                tv.setTextColor(Color.parseColor("#FF7733"));

            }else {
                tv.setBackgroundResource(R.drawable.gray_line_bg);
                tv.setTextColor(Color.parseColor("#666666"));
            }
        }

        return view;
    }
    public void setSeclection(int position) {
        clickStatus = position;
        this.notifyDataSetChanged();
    }

}
